package org.example.demo3.config;

import org.example.demo3.enums.ProductConditionEnum;
import org.springframework.core.convert.converter.Converter;

public class StringToProductConditionConverter implements Converter<String, ProductConditionEnum> {
    @Override
    public ProductConditionEnum convert(String source) {
        try {
            int code = Integer.parseInt(source);
            return ProductConditionEnum.fromCode(code);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("成色参数必须是数字");
        }
    }
}